#ifndef STREAMER_H
#define STREAMER_H

#include <QByteArray>
#include <QPair>

/**
 * @brief The Streamer class
 * @brief 数据流的打包与拆包，粘包
 */
class Streamer
{
public:
    Streamer();

    static QByteArray pack(int type, const QByteArray& data);
    bool unpack(int& type, QByteArray& data);

    inline void attach(const QByteArray& stream){ buffer += stream; }
    inline void clear(){ buffer.clear(); }

private:
    QByteArray buffer; // 缓存
};

#endif // STREAMER_H
